package com.language.points.multi.thread.num;

import java.util.Random;

/**
 * 多线程 - 加数据
 * @author yll
 * @version 1.0.0
 * @date 2024/04/12 13：35
 * @desc 加数据
 * */
public class NumAddThread implements Runnable {
    Numbers num = null;
    Integer count = 1000;
    public NumAddThread(Numbers num){
        this.num = num;
    }
    Random random = new Random();
    @Override
    public void run() {
        do{
//            synchronized (num) {
                num.addNum(1);
//            }
            try {
                Thread.currentThread().sleep(random.nextInt(10));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }while (count-- > 0);

        System.out.println(num);
    }

}
